package com.kucunProject.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kucunProject.model.User;
import com.kucunProject.service.JudgeUser;

public class login extends HttpServlet {


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String name = request.getParameter("j_username");
		String password = request.getParameter("j_password");
		JudgeUser ju = new JudgeUser();
		boolean flag = ju.judge(name,password);
		if(flag){
			User u = new User(name,password);
			HttpSession session = request.getSession();
			session.setAttribute("userInfo", u);
			RequestDispatcher rd = request
					.getRequestDispatcher("../homepage/index.jsp");
			rd.forward(request, response);
		}else{
			RequestDispatcher rd = request
					.getRequestDispatcher("../login.jsp");
			rd.forward(request, response);
		}
		
	}

}
